using System;
using System.Drawing;

namespace ImageCSharp.Core.Models
{
    /// <summary>
    /// 橡皮擦工具
    /// </summary>
    public class EraserTool : Tool
    {
        public EraserTool()
        {
            Type = ToolType.Eraser;
            Name = "橡皮擦工具";
            Description = "用于擦除图像内容";
            IconPath = "Eraser";
            
            Properties.Add("BrushSize", 10);
            Properties.Add("Hardness", 1.0f);
            Properties.Add("Opacity", 1.0f);
            Properties.Add("Mode", EraserMode.Normal);
            Properties.Add("AntiAlias", true);
        }

        public int BrushSize 
        { 
            get => (int)Properties["BrushSize"]; 
            set => Properties["BrushSize"] = Math.Max(1, Math.Min(100, value)); 
        }

        public float Hardness 
        { 
            get => (float)Properties["Hardness"]; 
            set => Properties["Hardness"] = Math.Max(0f, Math.Min(1f, value)); 
        }

        public float Opacity 
        { 
            get => (float)Properties["Opacity"]; 
            set => Properties["Opacity"] = Math.Max(0f, Math.Min(1f, value)); 
        }

        public EraserMode Mode 
        { 
            get => (EraserMode)Properties["Mode"]; 
            set => Properties["Mode"] = value; 
        }

        public bool AntiAlias 
        { 
            get => (bool)Properties["AntiAlias"]; 
            set => Properties["AntiAlias"] = value; 
        }

        /// <summary>
        /// 获取硬度百分比显示
        /// </summary>
        public string GetHardnessDisplay()
        {
            return $"{Hardness * 100:F0}%";
        }

        /// <summary>
        /// 获取不透明度百分比显示
        /// </summary>
        public string GetOpacityDisplay()
        {
            return $"{Opacity * 100:F0}%";
        }

        /// <summary>
        /// 获取擦除模式显示
        /// </summary>
        public string GetModeDisplay()
        {
            return Mode switch
            {
                EraserMode.Normal => "正常",
                EraserMode.Block => "块",
                EraserMode.Pencil => "铅笔",
                _ => "正常"
            };
        }
    }

    /// <summary>
    /// 橡皮擦模式
    /// </summary>
    public enum EraserMode
    {
        Normal,
        Block,
        Pencil
    }
}